from rest_framework import status
from rest_framework.pagination import PageNumberPagination
from rest_framework.response import Response
from rest_framework.templatetags.rest_framework import data
from rest_framework.views import APIView

from user.models import User
from user.serailizers import UserSerializer


class UserView(APIView):
    queryset = User.objects.all()

    serializer_class = UserSerializer

    pagination_class = PageNumberPagination

    PageNumberPagination.page_size_query_param = "rows"
    PageNumberPagination.page__query_param = 'page'
    def list(self, request, *args, **kwargs):
        queryset = self.get_queryset()
        page = self.paginate_queryset(queryset)
        seriliazer = self.serializer_class(page, many=True)
        return self.get_paginated_response(seriliazer.data)


class ModeViewSet:
    pass


class AddressView(ModeViewSet):
    def get(self, request, *args, **kwargs):
        if "pk" in kwargs:
            instance = self.get_object()
            serializer = self.serializer_class(instance=instance)

        serializer = self.get_serilizer(instance=self.get_queryset(), many=True)
        return Response(data=serializer.data)
    def post(self, request, *args, **kwargs):
        serializer = self.get_serilizer(data=request.data)
        serializer.is_valid(raise_exception=True)
        serializer.save()
        return Response(data=serializer.data, status=status.HTTP_201_CREATED)
    def put(self, request, *args, **kwargs):
        instance = self.get_object()
        serializer = self.get_serilizer(instance, data=request.data)
        serializer.is_valid(raise_exception=True)
        serializer.save()
        return Response(status=status.HTTP_204_NOT_CONTENT)  